﻿using UnityEngine;
using System.Collections;

public class SceneFadeInOut : MonoBehaviour
{
    public float fadeSpeed = 1.5f;          // Speed that the screen fades to and from black.
    
    void Awake ()
    {
        // Set the texture so that it is the the size of the screen and covers it.
        guiTexture.pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
    }    
    
    public bool FadeToClear ()
    {
        // Lerp the colour of the texture between itself and transparent.
        guiTexture.color = Color.Lerp(guiTexture.color, Color.clear, fadeSpeed * Time.deltaTime);
        return guiTexture.color.a <= 0.05f;
    }
    
    
    public bool FadeToBlack ()
    {
        // Lerp the colour of the texture between itself and black.
        guiTexture.color = Color.Lerp(guiTexture.color, Color.black, fadeSpeed * Time.deltaTime);
        return guiTexture.color.a >= 0.95f;
    }
    
    
    public void StartFadeIn ()
    {
        guiTexture.color = Color.black;
        guiTexture.enabled = true;
    }
    
    
    public void StartFadeOut ()
    {
        guiTexture.color = Color.clear;
        guiTexture.enabled = true;
     
    }
}
    